home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / sndppr3w.zip / SANDPAPR.DOC < prev    next >
Text File  |  1992-02-06  |  10KB  |  217 lines

  1. Sandpaper
  2. 4/26/91
  3. Mike Schoenborn
  4.  
  5. Sandpaper is a simple little utility that reads in triangle data, then
  6. outputs that same triangle data with surface normals appended.  This
  7. "polygon patch" or "smooth triangle" output can be used with a raytracing
  8. program to produce smooth looking surfaces, instead of the flat "faceted"
  9. look you get with triangles alone.  Consider the difference between a
  10. geodesic dome and a smooth sphere, and you'll have the idea. (I've included
  11. a tiny, simple GIF file as an example).
  12.  
  13. The input data should consist of numbers only, seperated by whitespace,
  14. in groups of 9; three numbers (x,y,z) per point, and three points per
  15. triangle.  Any other text _must_ be editted out ahead of time, or you'll
  16. get truncated, nonsense results. "Whitespace" simply means spaces, tabs,
  17. carriage returns, etc., so it's pretty flexible.
  18.  
  19. This... 1.0  2.0  3.0
  20.         4.0  5.0  6.0
  21.         7.0  8.0  9.0   works just as well as...
  22.  
  23. 1 2 3 4 5 6 7 8 9       which works as well as...
  24.  
  25. 1.0 2.0000
  26.         3 4
  27.  
  28.  5.  0006.0
  29.  
  30. 7.000 8e-0  9
  31.  
  32. The input routine is pretty forgiving, but I haven't really tried hard
  33. to break it.  Numbers only, in groups of nine.  (If the number of triangles
  34. coming out is the same as the number that went in, then things worked ok).
  35.  
  36.  
  37. Several output formats are available via a command line switch; currently:
  38.  
  39.         -n : NFF (MTV)
  40.         -v : Vivid
  41.         -d : DKBTrace (STAR)
  42.         -r : Rayshade
  43.  
  44. An example of each of these formats is given in the accompanying Sample.Doc.
  45. If no command line format option is specified, the output will be in "raw"
  46. form; just the triangles and normals without any other text.
  47.  
  48. (Note: "SMOOTH_TRIANGLES" in the current (2.10) version of DKBTrace don't
  49. work.  It's not this program, honest).
  50.  
  51. There are a few other command line switches available:
  52.  
  53. -q : Normally the program will display a count on the screen as the
  54.      triangles are read in.  This switch turns off the output.
  55.  
  56. -z : This will send debugging info to the output.  Unless you're poking
  57.      around in the source code, this probably won't be very interesting.
  58.  
  59. -h : These (or any unrecognized switches, for that matter) just show
  60. -? : brief usage instructions, "help".
  61.  
  62. An option may be given in upper or lower case, and is preceeded with a dash,
  63. forward slashe or backslashe.  Options may be grouped, as in "-rqz".
  64.  
  65.  
  66. Unlike programs that require named input and output files, this program acts
  67. as a "filter".  That is, it reads input data from the "standard input" (by
  68. default, the keyboard) and sends the results to the "standard output" (by
  69. default, the screen).  This may be familiar to those that are accustomed to
  70. working with "pipes", but for others, here's a simple example:
  71.  
  72.         C:\TRACERS\>type input.raw | sp -d > tri.dat
  73.  
  74. This will take raw triangle data from the file "input.raw", "pipe" it through
  75. the Sandpaper "filter" utility, then put the output into the file "tri.dat".
  76. (If the "tri.dat" file already existed, it would be overwritten).
  77.  
  78. If you're unfamiliar with how this works, and are curious enough to find out,
  79. see a DOS manual (the "more" and "sort" commands work the same way).
  80. Otherwise just do it like the example and forget about it.
  81.  
  82. Caution: If you just type "sp <cr>", nothing will seem to happen.  What
  83. it's doing it waiting for something to come in from the "standard input"
  84. which, in this case, would be your keyboard.  Actually, you *could* go ahead
  85. and type in the data by hand, but that's entirely up to you.
  86.  
  87.  
  88. Memory Considerations ---
  89.  
  90. Sorry, it's impossible to say (simply) exactly how much memory is required
  91. to run this program.  The memory requirements are determined by the number of
  92. triangles and number of points, obviously, but also by how the triangles are
  93. arranged, the number of points which are unique, which points belong to which
  94. triangles...
  95.  
  96. Consider these two figures...
  97.            _______                  _____________________________________
  98.          / \     / \               / \         / \         / \         /
  99.        /    \   /    \           /     \     /     \     /     \     /
  100.      /_______\/________\       /         \ /         \ /         \ /
  101.      \       /\       /       -------------------------------------
  102.        \    /   \    /      
  103.          \/_______\/        
  104.  
  105. 6 triangles                             6 triangles
  106. 7 unique points                         8 unique points
  107. 6 points belong to only 2 tri's         2 points belong to only 1 tri
  108. 1 point belongs to 6 tri's              2 points belong to 2 tri's
  109.                                         4 points belong to 3 tri's
  110.  
  111. Since the program doesn't know how the input triangles are going to be
  112. arranged, it can't plan ahead of time on how to balance the memory allocation
  113. for the triangles, points, and (most awkwardly) the "belongs to" information.
  114. I suppose it could have been written to use some arbitrarily huge tables based
  115. on some arbitrarily presumptuous assumptions...but it wasn't.  Instead, it uses
  116. a linked list way of doing things, and seems to work.  Complain if you must,
  117. but back it up with new source code.
  118.  
  119. I've sent a data set of more than 700 triangles through and the program had
  120. no problem with it.  It will definately handle a lot, but you just can't be
  121. exact as to how much "a lot" actually is.  If it does run out of memory, it
  122. will abort with a message saying how much it did handle before choking.
  123. (The data, btw, was from Marco Reinig's mods to FractInt...the result was a
  124. delightfully smooth, almost "melted" looking, Mt.Mandlebrot :-).
  125.  
  126. If you do run out of memory, you have a couple of options.  One is to modify
  127. the source for large model, far pointers, etc.  Another, probably better
  128. idea, is to split up the data into multiple groups and process each group
  129. seperately.  If you go this route, consider the layout of your data and keep
  130. in mind that the normals are calculated based on adjoining triangles only.
  131. You could split your data, allowing a 1 triangle overlap at the split, process
  132. each group, then remove the overlap duplicate data when you recombine the
  133. outputs.
  134.  
  135. Errors Messages ---
  136.  
  137. This program is really so simple its hard to screw things up.
  138.  
  139. If you specify more than one output format switch, it will gripe and abort.
  140.  
  141. If it runs out of memory, it will tell you so, and abort.
  142.  
  143. If you ignore the input formatting rules (such as they are) it will punish
  144. you by going ahead to produce output that is all wrong (but attractively
  145. formated) and allow you to waste precious time raytracing with it.
  146. Garbage in, garbage out.
  147.  
  148.  
  149. ********************** DISCLAIMERS, COPYRIGHT, ETC ************************
  150.  
  151.                                 <none>
  152.  
  153. Or, as a friend once said "You break it, you bought it". (This is the
  154. same fellow, btw, that once told me: "Any jumbo, sufficiently large, is
  155. indistinguishable from mumbo"...so, consider the source).  If this breaks
  156. something its not suppose to, I'm very sorry, but not liable.  Whaddya want,
  157. I'm giving you the source code, for crying out loud.  And if you want
  158. something official, here it is: "This program is public domain".  Sheesh.
  159.  
  160.  
  161. Enhancements ---
  162.  
  163. None planned, but I'm open to suggestions.  A few things that might be
  164. nice would be:
  165.  
  166.         Support for additional tracer formats as the need arises (this
  167.         is *real* simple to implement).
  168.  
  169.         Allowing "-i" and "-o" options to specify input and output file
  170.         names for those uncomfortable with piping.
  171.  
  172.         Rework the code for far pointers and large model.  I started
  173.         on this but things began to break, so I backed off.
  174.  
  175.         The ability to take an existing tracer input file, process whatever
  176.         triangles are there, and fold the results back into the original.
  177.  
  178.         An alternate name for the program that isn't so _damn_ cute.
  179.  
  180.         Some optimization for speed or size.  I really made no attempt to
  181.         optimize this, at the source level nor at compile time.  There are
  182.         plenty of places where a variable is filled in one statement, then
  183.         tested seperately in the next.  Big deal, the source is readable.
  184.         I'm sure there are cpu-state counters that would like to see every
  185.         last bit of performance wringed out of this, but it runs plenty
  186.         fast for me and I have better things to get into.
  187.  
  188.         Docs suggesting ways of generating raw triangles in the first place.
  189.  
  190.  
  191. I hope you like it,
  192.  
  193. Mike Schoenborn
  194. CIS: [70010,147] COMART Forum/Raytrace Section
  195. (or somewhat less reliably: mjs@schoen.UUCP)
  196.  
  197.  
  198. Change List
  199.  
  200. 10/28/91        Function end_of_list() didn't check for being passed a
  201.                 NULL pointer.  This has been fixed and the program now
  202.                 compiles cleanly with all memory models.  The sp.exe
  203.                 executable was compiled with the compact memory model
  204.                 which should allow quite large data sets to be processed.
  205.                 The Vivid output format has also been changed to conform
  206.                 to version 2.0.                 Stephen Coy
  207.                                                 70413,136
  208.                                                 coy@ssc-vax.boeing.com
  209.  
  210.  
  211. 1/20/92         Added Vivid 1.0(-o commandline) and PoV output(-p).  PoV is
  212.                 the same as DKB only lowercase. 
  213.                                                 Steven Cox
  214.                                                 The Graphics Alternative
  215.                                                 (510) 524-2780
  216. /* eof */
  217.